package com.example.myinventory.ui.navigation

import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.example.myinventory.ui.home.HomeDestination
import com.example.myinventory.ui.home.HomeScreen
import com.example.myinventory.ui.item.ItemDetailsDestination
import com.example.myinventory.ui.item.ItemDetailsScreen
import com.example.myinventory.ui.item.ItemEditDestination
import com.example.myinventory.ui.item.ItemEditScreen
import com.example.myinventory.ui.item.ItemEntryDestination
import com.example.myinventory.ui.item.ItemEntryScreen

@Composable
fun InventoryNavHost(
    navController: NavHostController,
    modifier: Modifier = Modifier,
) {
    NavHost(
        navController = navController,
        startDestination = HomeDestination.route,
        modifier = modifier
    ) {
        composable(HomeDestination.route) {
            HomeScreen(
                navToItemEntry = { navController.navigate(ItemEntryDestination.route) },
                navToItemDetails = { navController.navigate("${ItemDetailsDestination.route}/$it") }
            )
        }

        composable(
            ItemEntryDestination.route,
            enterTransition = { slideInHorizontally { it } },
            exitTransition = { slideOutHorizontally { it } }
        ) {
            ItemEntryScreen(
                onNavigateUp = { navController.navigateUp() }
            )
        }

        composable(
            ItemDetailsDestination.routeWithArgs,
            arguments = listOf(navArgument(ItemDetailsDestination.itemIdArg) {
                type = NavType.IntType
            })
        ) {
            ItemDetailsScreen(
                navigateToEditItem = { navController.navigate("${ItemEditDestination.route}/$it") },
                navigateBack = { navController.navigateUp() }
            )
        }

        composable(
            ItemEditDestination.routeWithArgs,
            arguments = listOf(navArgument(ItemEditDestination.itemIdArg) {
                type = NavType.IntType
            })
        ) {
            ItemEditScreen(
                navigateBack = { navController.navigateUp() }
            )
        }
    }
}